// 修复时间格式化函数，支持解析字符串和 Date 对象
export function formatDate(input, format = 'YYYY-MM-DD HH:mm:ss') {
  const padZero = (num) => (num < 10 ? '0' + num : num);

  // 确保输入是 Date 对象
  const date = typeof input === 'string' || typeof input === 'number' ? new Date(input) : input;

  if (isNaN(date.getTime())) {
    console.error('Invalid date input:', input);
    return 'Invalid Date';
  }

  const year = date.getFullYear();
  const month = padZero(date.getMonth() + 1); // 月份从0开始
  const day = padZero(date.getDate());
  const hours = padZero(date.getHours());
  const minutes = padZero(date.getMinutes());
  const seconds = padZero(date.getSeconds());

  return format
    .replace('YYYY', year)
    .replace('MM', month)
    .replace('DD', day)
    .replace('HH', hours)
    .replace('mm', minutes)
    .replace('ss', seconds);
}